<?php
	class Page_help extends V_View {
        function index () {
        	$help=V_DB::fetch('SELECT page_text FROM v_system_pages WHERE page_name="help"');
            if (!empty($help))
            	$help_text=$help['page_text'];
            else $help_text='';
            $this->assign('help_text',$help_text);
        	$this->assign('page_title','Справка');
        	$this->display('header.tpl');
            $this->display('pages/help/index.tpl');
            $this->display('footer.tpl');
        }
		function edit () {
			if (isset($_POST['edit_help'])) {
				$help_text=$_POST['edit_help'];
				$result=V_DB::query('SELECT id FROM v_system_pages WHERE page_name="help"');
            	if (isset($result)) {
            		$help=V_DB::fetch_array($result);
            		$help_id=$help['id'];
            		if (V_DB::update('v_system_pages',$help_id,Array(
                		Array ('name' => 'page_text','value' => '"'.V_DB::escape($help_text).'"'),
                	)));
            	} else {
            		V_DB::inser('v_system_pages',Array(
            			Array ('name' => 'page_name','value' => '"help"'),
                		Array ('name' => 'page_text','value' => '"'.V_DB::escape($help_text).'"')
                	));
            	}
			} else {
				$result=V_DB::query('SELECT page_text FROM v_system_pages WHERE page_name="help"');
            	if (isset($result)) {
            		$help=V_DB::fetch_array($result);
            		$help_text=$help['page_text'];
            	} else $help_text='';
			}
			$this->assign('page_title','Редактирование страницы справки');
			$this->assign('help_text',$help_text);
        	$this->display('header.tpl');
            $this->display('pages/help/edit.tpl');
            $this->display('footer.tpl');
        }
        
}